package com.kuwou.workobject.service.Impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.kuwou.workobject.mapper.CommentMapper;
import com.kuwou.workobject.pojo.entity.Comment;
import com.kuwou.workobject.pojo.vo.CommentVo;
import com.kuwou.workobject.service.CommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {

    private final CommentMapper commentMapper;

    @Override
    public void truncateTable() {
        commentMapper.truncateTable();
    }

    @Override
    public List<CommentVo> getRankListComment(int rankListId) {
        LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<Comment>()
                .setEntityClass(Comment.class)
                .eq(Comment::getRankListId, rankListId);
        List<Comment> comments = Db.list(queryWrapper);
        return BeanUtil.copyToList(comments, CommentVo.class);
    }
}
